var pages = 1;
var loading = false; //状态标记
$(function() {
    loadlist();
    console.log("loadlist1");
})

var vm = new Vue({
			el: "#app",
			data: {
				num:"",
				sum:"",
				checkSort: false,
				checkBrand: false,
             //标记筛选条件
				checkSortItem:0,
				checkBrandItem:0,


				sort:"种类",
				brand:"位置",
				price:"799",
				changFlag:1,

                //数据
                orderList:[],
                //条件
                sortList:[],
                brandList:[],
                //条件值
                sortItem:"不限",
                brandItem:"不限",

			},
			mounted: function() {
				this.$nextTick(function() {
                    vm.listView();
				});

			},
			methods: {
                listView:function (n) {
                    var _this=this;
                    this.$http.get("lists",{"flag":1}).then(function (res) {
                        //console.log(res.data);
                        _this.sortList=res.data;

                    });
                    this.$http.get("lists",{"flag":2}).then(function (res) {
                        //console.log(res.data);
                        _this.brandList=res.data;

                    });

                },
				count:function () {
                    if(this.num == ""){
                        alert("建筑面积不能为空");
                    }else {
                        this.sum=this.num*this.price*1.03410+ "元";
                    }

                },

                //筛选头选中
				checkSelect: function(n) {
					
					if(n == 1) {
						this.checkSort = !this.checkSort;
						this.checkBrand=false;
						
					}
					if(n == 2) {
						this.checkBrand = !this.checkBrand;
						this.checkSort=false;

					}
                  
				},
				itemCheck:function(n,item,index){
					if(n==1){
						// this.sort=e.target.innerText;
						// this.checkSortItem=true;
						// this.checkSort=false;
                        this.sort=item.name;
                        this.checkSortItem=index;
                        this.checkSort=false;
                        this.sortItem=item.name;
                        console.log(this.sortItem);
                        pages=1;
                        loadlist();

						
					}
					if(n==2){
						this.brand=item.name;
						this.checkBrandItem=index;
						this.checkBrand=false;
                        this.brandItem=item.name;
                        console.log(this.brandItem);
                        pages=1;
                        loadlist();
					}

					
				},
				checkOver:function(){
					this.checkSort=false;
					this.checkBrand=false;

				},
			}
		});




//============================滚动加载
$("body").infinite(50).on("infinite", function() {
    console.log("加载")
    if(loading) return;
    loading = true;
    pages++; //页数
    $('.weui-loadmore').show();
    setTimeout(function() {
        loadlist();
        loading = false;
    }, 1000); //模拟延迟
});
var i=0;
function loadlist() {
    console.log("刷新方法"+i);
    console.log("页数"+pages);
    i++;
    var str="";
    $.ajax({
        type:"post",
        url:"myorder",
        dataType:'JSON',
        data:{sort:vm.sortItem,brand:vm.brandItem,page:pages},
        error: function (){
            $(".weui-loadmore").hide();
            str += " <div class=\"weui-cells__title\" style=\"text-align: center\">\n" +
                "                   <div class=\"live live-kulian\" style=\"font-size: 100px\"></div>\n" +
                "                    <div style=\"font-size: 30px\">暂无数据</div>\n" +
                "                </div>\n";
            $("#list").html(str);
        },
        success: function (data) {

            console.log(data);
            if (data.length > 0){
                if(pages==1){
                    vm.orderList=data;
                }
                else{
                    vm.orderList=vm.orderList.concat(data);
                }
                $("#listend").html("");
            }
            else {
                if(pages==1){
                    vm.orderList=[];
                }
                str += "<div class=\"weui-cells__title\" style=\"text-align: center\">\n" +
                    "                    暂无更多数据\n" +
                    "                </div>";
                $("#listend").html(str);
                loading = true;
            }
            $(".weui-loadmore").hide();
        }
    });

}
$(".jf").click(function(){

    $(this).find('img').attr('src','/static/images/jf1.png');
    $(".xf").find('img').attr('src','/public/static/images/xf2.png');
    vm.price="699";


});
$(".xf").click(function(){

    $(this).find('img').attr('src','/static/images/xf1.png');
    $(".jf").find('img').attr('src','/static/images/jf2.png');
    vm.price="799";

});